package com.hyc.myvideo.ui.fragment.homefargment;


import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.flyco.tablayout.SlidingTabLayout;
import com.hyc.myvideo.R;
import com.hyc.myvideo.data.adapter.MyPagerAdapter;
import com.hyc.myvideo.data.api.model.ModelLiveType;
import com.hyc.myvideo.ui.base.BaseFragment;
import com.hyc.myvideo.ui.fragment.live.LiveViewFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 直播
 * @author gyb
 * @version 1.0
 * @created 2017/06/16
 */
public class LiveFragment extends BaseFragment {
    @BindView(R.id.fragment_table_live)SlidingTabLayout mTable;
    @BindView(R.id.fragment_pager_live)ViewPager mPager;
    @BindView(R.id.head_center_title)TextView textTitle;
    private List<ModelLiveType> mTitles = null;
    private List<BaseFragment> fragments  = new ArrayList<>();
    private MyPagerAdapter mAdapter;
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_live;
    }

    @Override
    protected void initView() {
        textTitle.setVisibility(View.VISIBLE);
        textTitle.setText("直播");
        getmTitles();
        createFragment(mTitles);
        mAdapter = new MyPagerAdapter(fragments,mTitles,getFragmentManager(),getActivity());
        mPager.setOffscreenPageLimit(mTitles.size());
        mPager.setAdapter(mAdapter);
        mTable.setViewPager(mPager);
    }

    @Override
    protected void initData() {

    }

    @Override protected void onNexts(String result, String method){

    }

    @Override protected void onError() {

    }

    private void getmTitles(){
        mTitles = new ArrayList<>();
        mTitles.add(new ModelLiveType("0","全部"));
        mTitles.add(new ModelLiveType("15","养生课堂1"));
        mTitles.add(new ModelLiveType("22","养生课堂2"));
        mTitles.add(new ModelLiveType("33","养生课堂3"));
        mTitles.add(new ModelLiveType("44","养生课堂4"));
        mTitles.add(new ModelLiveType("56","养生课堂5"));
        mTitles.add(new ModelLiveType("65","养生课堂6"));
    }

    /***
     *动态创建 BaseFragment
     * @return
     */
    private List<BaseFragment> createFragment(List<ModelLiveType> liveList){
        int length = liveList.size();
        for (int i = 0; i < length; i++) {
            BaseFragment fragment = LiveViewFragment.newInstance(liveList.get(i).getId());
            fragments.add(fragment);
        }
        return fragments;
    }
}
